<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
<title></title>
</head>

<body>
<script type="text/javascript">
var str="123-45";
var pattern=/^\d{3}-\d{2}$/;
if(pattern.test(str)){
	alert("字符串符合指定的格式");
}else{
	alert("字符串不符合指定的格式");
}
</script>
</body>
</html>
